package com.ruoyi.car.controller.carmanage;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

import com.car.pojo.TbCarKind;
import com.car.pojo.TbCarMain;
import com.car.pojo.TbCarPreconfigured;
import com.car.pojo.TbCarType;
import com.ruoyi.car.service.carmanage.ITbCarMainService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆主要信息Controller
 *
 * @author 韩昊昌
 * @date 2020-06-25
 */
@Controller
@RequestMapping("/carmain/carmain")
public class TbCarMainController extends BaseController
{
    private String prefix = "car";

    @Autowired
    private ITbCarMainService tbCarMainService;



    @RequiresPermissions("carmain:carmain:view")
    @GetMapping()
    public String carmain()
    {
        return prefix + "/carmain";
    }

    /**
     * 查询车辆主要信息列表
     */
    @RequiresPermissions("carmain:carmain:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbCarMain tbCarMain)
    {
        startPage();
        List<TbCarMain> list = tbCarMainService.selectTbCarMainList(tbCarMain);
        return getDataTable(list);
    }

    /**
     * 车辆种类回显
     */
    @GetMapping("/carkind")
    @ResponseBody
    public List<TbCarKind> carkind(ModelMap mmap)
    {
        List<TbCarKind> tbcarkind = tbCarMainService.cartype();
        mmap.put("carkindList", tbcarkind);
        return tbcarkind;
    }

    /**
     * 回显车辆主表数据
     */
    @PostMapping("/carMainFindOne")
    @ResponseBody
    public TbCarPreconfigured carMainFindOne(Integer id)
    {
        System.out.println(id);
        TbCarPreconfigured tbCarPreconfigured = tbCarMainService.carMainFindOne(id);
        return tbCarPreconfigured;
    }

    /**
     * 跳转地图页面
     */
    @GetMapping("/goMap")
    public String geMap(){
        return prefix + "/ditu";
    }


    /**
     * 导出车辆主要信息列表
     */
    @RequiresPermissions("carmain:carmain:export")
    @Log(title = "车辆主要信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbCarMain tbCarMain)
    {
        List<TbCarMain> list = tbCarMainService.selectTbCarMainList(tbCarMain);
        ExcelUtil<TbCarMain> util = new ExcelUtil<TbCarMain>(TbCarMain.class);
        return util.exportExcel(list, "carmain");
    }

    /**
     * 新增车辆主要信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆主要信息
     */
    @RequiresPermissions("carmain:carmain:add")
    @Log(title = "车辆主要信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbCarMain tbCarMain)
    {
        return toAjax(tbCarMainService.insertTbCarMain(tbCarMain));
    }

    /**
     * 修改车辆主要信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbCarMain tbCarMain = tbCarMainService.selectTbCarMainById(id);
        mmap.put("tbCarMain", tbCarMain);
        return prefix + "/edit";
    }


    /**
     * 修改保存车辆主要信息
     */
    @RequiresPermissions("carmain:carmain:edit")
    @Log(title = "车辆主要信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbCarMain tbCarMain)
    {
        return toAjax(tbCarMainService.updateTbCarMain(tbCarMain));
    }

    /**
     * 删除车辆主要信息
     */
    @RequiresPermissions("carmain:carmain:remove")
    @Log(title = "车辆主要信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbCarMainService.deleteTbCarMainByIds(ids));
    }

    /**
     * ajax回显List<TbCarMain>信息
     * @return
     */
    @GetMapping("/findAll")
    @ResponseBody
    public List<TbCarMain> findAll()
    {
        List<TbCarMain> list = tbCarMainService.selectTbCarMainList(null);
        return list;
    }



}
